home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / picture / screen.c < prev    next >
Text File  |  1993-09-23  |  5KB  |  159 lines

  1. //    Copyright 1993 Ralph Gonzalez
  2.  
  3. /*
  4. *    FILE:        screen.c
  5. *    AUTHOR:        R. Gonzalez
  6. *    CREATED:    Aug. 5, 1990
  7. *
  8. *    generic methods for multi-window screens.  
  9. */
  10.  
  11. # include    "screen.h"
  12. # include    "error.h"
  13. # include    <stdlib.h>
  14.  
  15. extern Error    *gerror;
  16.  
  17. /******************************************************************
  18. *    Initialize screen.  Derived classes initialize device_frame.
  19. ******************************************************************/
  20. Generic_Screen::Generic_Screen(void)
  21. {
  22.     device_frame = new Frame;
  23.     normalized_frame = new Frame;
  24.     set_normalized_frame(0.,0.,2.,2.);
  25.     num_windows = 0;
  26. }
  27.  
  28. /******************************************************************
  29. *    Add new window to screen - up to derived class.
  30. ******************************************************************/
  31. int        Generic_Screen::new_window(Frame *frame)
  32. {
  33.     return    0; // must return something in Turbo C++? 
  34. }
  35.  
  36. /******************************************************************
  37. *    Bring window to front.  This is up to the derived class.
  38. ******************************************************************/
  39. void    Generic_Screen::make_closest(int window_num)
  40. {
  41. }
  42.  
  43. /******************************************************************
  44. *    Get coordinate frame of window in device coordinates.
  45. *    Up to derived class.
  46. ******************************************************************/
  47. void    Generic_Screen::get_window_device_frame(int window_num,
  48.                                         Frame *frame)
  49. {
  50. }
  51.  
  52. /******************************************************************
  53. *    Return screen aspect ratio: width/height in device coords.
  54. ******************************************************************/
  55. double    Generic_Screen::get_device_aspect_ratio(void)
  56. {
  57.     double    ratio;
  58.     
  59.     ratio = device_frame->width/device_frame->height;
  60.     if (ratio > 0.)
  61.         return ratio;
  62.     else
  63.         return -ratio;
  64. }
  65.  
  66. /******************************************************************
  67. *    Change coordinate system for windows and drawing routines.
  68. *    This is in terms of the width, height, and origin of
  69. *    the desired coordinate system for the whole screen.  Use
  70. *    get_device_aspect_ratio to maintain aspect ratio.
  71. ******************************************************************/
  72. void    Generic_Screen::set_normalized_frame(double x,double y,
  73.                                     double width,double height)
  74. {
  75.     normalized_frame->set(x,y,width,height);
  76. }
  77.  
  78. /******************************************************************
  79. *    Sets the current drawing window.  Up to derived class.
  80. ******************************************************************/
  81. void    Generic_Screen::set_current_window(int window_num)
  82. {
  83. }
  84.  
  85. /******************************************************************
  86. *    Sets the current drawing pen color.  Up to derived class.
  87. ******************************************************************/
  88. void    Generic_Screen::set_pen_color(color x)
  89. {
  90. }
  91.  
  92. /******************************************************************
  93. *    Sets window background to current color.  Up to derived class. 
  94. ******************************************************************/
  95. void    Generic_Screen::fill_window(void)
  96. {
  97. }
  98.  
  99. /******************************************************************
  100. *    draw_line() is used to draw lines using device coordinates.
  101. ******************************************************************/
  102. void    Generic_Screen::draw_line(Coord2* c1,Coord2* c2)
  103. {
  104.     move_to(c1);
  105.     draw_to(c2);
  106. }
  107.  
  108. /******************************************************************
  109. *    Move present pen position to new position using device
  110. *    coordinates.  Nothing is drawn.  Up to derived class.
  111. ******************************************************************/
  112. void    Generic_Screen::move_to(Coord2* c)
  113. {
  114. }
  115.  
  116. /******************************************************************
  117. *    Draw from present pen position to new position using device
  118. *    coordinates.  Up to derived class.
  119. ******************************************************************/
  120. void    Generic_Screen::draw_to(Coord2* c)
  121. {
  122. }
  123.  
  124. /******************************************************************
  125. *    mouse_button_is_down() checks whether the mouse button is down,
  126. *    returns TRUE if so, FALSE if not.  Up to derived class.  Make
  127. *    sure to override this if you use Screen::wait(), or override
  128. *    Screen::wait().  (Else you'll get an infinite "wait"!)
  129. ******************************************************************/
  130. boolean    Generic_Screen::mouse_button_is_down(void)
  131. {
  132.     return FALSE;
  133. }
  134.  
  135. /******************************************************************
  136. *    Wait until button is pressed.
  137. ******************************************************************/
  138. void    Generic_Screen::wait(void)
  139. {
  140.     while (!mouse_button_is_down())
  141.         ;
  142.     while (mouse_button_is_down())
  143.         ;
  144. }
  145.  
  146. /******************************************************************
  147. *    Destroy screen.
  148. ******************************************************************/
  149. Generic_Screen::~Generic_Screen(void)
  150. {
  151.     delete device_frame;
  152.     delete normalized_frame;
  153. }
  154.  
  155.   
  156.  
  157.  
  158.  
  159.